<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>2018/12/5</title>
    <script src="../node_modules/axios/dist/axios.min.js"></script>
    <!--好的代码像粥一样,是得用时间和精力熬的。-->
</head>
<body>
<input type="text" placeholder="title">
<textarea></textarea>
<input type="text" placeholder="comment">
<input type="number" placeholder="fav">
<button>提交</button>
</body>
<script>
    window.onload = function () {
        let ipt = document.getElementsByTagName('input');
        let textarea = document.getElementsByTagName('textarea')[0];
        let btn = document.getElementsByTagName('button')[0];
        btn.addEventListener('click',function () {
            axios.post('http://localhost:8080/article', {
                title: ipt[0].value,
                content: textarea.value,
                date: new Date().getTime(),
                fav: ipt[2].value,
            }).then(data => {console.log(data)})
                .catch(error => { console.log(error)})
        })
    }
</script>
</html>
